#ifndef SQLPARSER_SELECT_STATEMENT_H
#define SQLPARSER_SELECT_STATEMENT_H

#include "SQLStatement.h"
#include "Stat.h"
#include "Table.h"
#include "../Dict.h"

namespace ment {

	enum OrderType {
		kOrderAsc,
		kOrderDesc
	};

	// Description of the order by clause within a select statement.
	struct OrderDescription {
		OrderDescription(OrderType type, Stat* stat);
		virtual ~OrderDescription();
		OrderType type;
		Stat* stat;
	};

	const int64_t kNoLimit = -1;
	const int64_t kNoOffset = -1;

	// Description of the limit clause within a select statement.
	struct LimitDescription {
		LimitDescription(int64_t limit, int64_t offset);
		int64_t limit;
		int64_t offset;
	};

	// Description of the group-by clause within a select statement.
	struct GroupByDescription {
		GroupByDescription();
		virtual ~GroupByDescription();
		std::vector<Stat*>* columns;
		Stat* having;
	};

	// Representation of a full SQL select statement.
	// TODO: add union_order and union_limit.
	struct SelectStatement : SQLStatement {
		SelectStatement();
		virtual ~SelectStatement();
		virtual std::string execute(std::string username = "default");


		TableRef* fromTable;
		bool selectDistinct;
		std::vector<Stat*>* selectList;
		Stat* whereClause;
		GroupByDescription* groupBy;

		SelectStatement* unionSelect;
		std::vector<OrderDescription*>* order;
		LimitDescription* limit;




		//9.12.1
		int whereLine = -1;
		int whereColumn = -1;

		int eqOpLine = -1;
		int eqOpColumn = -1;
	};

} // namespace ment

#endif
